import { ApiProperty } from "@nestjs/swagger";
import { $Enums, SysUser } from "@prisma/client";
import { Transform } from "class-transformer";
import {
    IsEmail,
    IsEnum,
    IsNotEmpty,
    IsNumberString,
    IsOptional,
    IsString,
    Length,
    Matches,
    MinLength
} from "class-validator";

export class UpdateSysUserProfileDto
    implements Pick<SysUser, "username" | "email" | "phone" | "nickname" | "realname" | "gender">
{
    @IsOptional()
    @Transform(({ value }) => value.trim())
    @Matches(/^[a-zA-Z0-9_]+$/, { message: "用户名只能包含字母、数字、下划线" })
    @IsString()
    @IsNotEmpty({ message: "用户名不能为空" })
    @MinLength(1, { message: "用户名至少1个字符" })
    @ApiProperty({
        description: "登录用户名，用户名只能包含字母、数字、下划线",
        example: "JohnDoe",
        required: true
    })
    username: string;

    @IsOptional()
    @IsEmail({}, { message: "邮箱格式不正确" })
    @IsNotEmpty({ message: "邮箱不能为空" })
    @ApiProperty({
        description: "邮箱地址",
        example: "john.doe@example.com",
        required: true
    })
    email: string;

    @IsOptional()
    @IsString()
    @IsNotEmpty({ message: "昵称不能为空" })
    @MinLength(1, { message: "昵称至少1个字符" })
    @ApiProperty({
        description: "昵称",
        example: "用户123",
        required: true
    })
    nickname: string;

    @IsOptional()
    @IsString()
    @IsNotEmpty({ message: "真实姓名不能为空" })
    @MinLength(1, { message: "真实姓名至少1个字符" })
    @ApiProperty({
        description: "真实姓名",
        example: "张三",
        required: true
    })
    realname: string;

    @IsOptional()
    @IsNumberString()
    @IsOptional()
    @Length(11, 11)
    @ApiProperty({
        description: "手机号",
        example: "13800138000",
        required: false
    })
    phone: string;

    @IsOptional()
    @IsEnum($Enums.Gender)
    @ApiProperty({
        example: "male",
        description: "性别",
        enum: $Enums.Gender,
        required: false
    })
    gender: $Enums.Gender;
}
